$OpenBSD: patch-filters_c,v 1.3 2010/05/24 22:17:03 espie Exp $
--- filters.c.orig	Sat Oct 31 04:58:47 1998
+++ filters.c	Sat May 22 16:47:47 2010
@@ -103,9 +103,12 @@ block_url(struct http_request *http, struct client_sta
 					n += strlen(path);
 					n += strlen(spec);
 
-					p = malloc(n);
+					if ((p = malloc(n)) == NULL) {
+					   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+					   exit(-1);
+					}
 
-					sprintf(p, CBLOCK,
+					snprintf(p, n, CBLOCK,
 						hostport, path, spec);
 
 					freez(hostport);
@@ -174,9 +177,12 @@ trust_url(struct http_request *http, struct client_sta
 					n += strlen(path);
 					n += strlen(referrer);
 
-					p = malloc(n);
+					if ((p = malloc(n)) == NULL) {
+					   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+					   exit(-1);
+					}
 
-					sprintf(p, CTRUST,
+					snprintf(p, n, CTRUST,
 						hostport, path, referrer);
 
 					freez(hostport);
@@ -288,8 +294,11 @@ trust_url_not_trusted:
 	n += strlen(path);
 	n += strlen(referrer);
 
-	p = malloc(n);
-	sprintf(p, CTRUST, hostport, path, referrer);
+	if ((p = malloc(n)) == NULL) {
+	   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+	   exit(-1);
+	}
+	snprintf(p, n, CTRUST, hostport, path, referrer);
 
 	freez(hostport);
 	freez(path);
@@ -441,8 +450,11 @@ dsplit(char *domain)
 	/* save a copy of the pointers in dvec */
 	size = ret->dcnt * sizeof(*ret->dvec);
 		
-	if((ret->dvec = malloc(size))) {
+	if((ret->dvec = malloc(size)) != NULL) {
 		memcpy(ret->dvec, v, size);
+	} else {
+	   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+	   exit(-1);
 	}
 
 	return(*ret);
@@ -562,8 +574,11 @@ ij_blocked_url(struct http_request *http, struct clien
 	n += strlen(path    );
 	n += strlen(pattern );
 
-	if((p = malloc(n))) {
-		sprintf(p, template, hostport, path, pattern);
+	if((p = malloc(n)) != NULL) {
+		snprintf(p, n, template, hostport, path, pattern);
+	} else {
+	   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+	   exit(-1);
 	}
 
 	freez(hostport);
@@ -618,8 +633,11 @@ ij_untrusted_url(struct http_request *http, struct cli
 	n += strlen(hostport);
 	n += strlen(path    );
 
-	if((p = malloc(n))) {
-		sprintf(p, template, hostport, path);
+	if((p = malloc(n)) != NULL) {
+		snprintf(p, n, template, hostport, path);
+	} else {
+	   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+	   exit(-1);
 	}
 
 	freez(hostport);
@@ -632,25 +650,25 @@ ij_untrusted_url(struct http_request *http, struct cli
 	p = strsav(p, "<h3>The following referrers are trusted</h3>\n");
 
 	for(tl = trust_list; (t = *tl) ; tl++) {
-		sprintf(buf, "%s<br>\n", t->spec);
+		snprintf(buf, sizeof(buf), "%s<br>\n", t->spec);
 		p = strsav(p, buf);
 	}
 
 	if(trust_info->next) {
 		struct list *l;
 
-		strcpy(buf,
+		strlcpy(buf,
 			"<p>"
 			"You can learn more about what this means "
 			"and what you may be able to do about it by "
 			"reading the following documents:<br>\n"
-			"<ol>\n"
+			"<ol>\n", sizeof(buf)
 		);
 
 		p = strsav(p, buf);
 		
 		for(l = trust_info->next; l ; l = l->next) {
-			sprintf(buf,
+			snprintf(buf, sizeof(buf),
 				"<li> <a href=%s>%s</a><br>\n",
 					l->str, l->str);
 			p = strsav(p, buf);
